#include "PixelBuffer.h"

PixelBuffer::PixelBuffer()
{
    PBuffer = NULL;
}

void PixelBuffer::loadImage(QImage image)
{
    if (PBuffer != NULL) {
        delete PBuffer;
        PBuffer = NULL;
    }
    PBuffer = new QGLPixelBuffer(image.width(), image.height(), QGLFormat());
    PBuffer->makeCurrent();
    ImageToLoad = QGLWidget::convertToGLFormat(image);
}

void PixelBuffer::renderImage()
{
    glDrawPixels(ImageToLoad.width(), ImageToLoad.height(), GL_RGBA, GL_UNSIGNED_BYTE, ImageToLoad.bits());
}

QImage PixelBuffer::extractImage()
{
    return PBuffer->toImage();
}

